package cn.edu.xmu.tangzk.scala.s99

object P13 {

    def encodeDirect[A](ls: List[A]): List[(Int, A)] = {
        if (ls.isEmpty) Nil
        else {
            val (packed, next) = ls span { _ == ls.head }
            (packed.length, packed.head) :: encodeDirect(next)
        }
    }

    def main(args: Array[String]) {
        println(encodeDirect(List('a, 'a, 'a, 'a, 'b, 'c, 'c, 'a, 'a, 'd, 'e, 'e, 'e, 'e)))
    }

}